<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>生成器</title>
</head>
<body>
<script>
    //生成器是特殊的一种函数
    //异步编程
    //yield是函数代码的分隔符
    function * gen(){

        console.log(11);
        yield 'aa';
        console.log(22)
        yield 'bb';
        console.log(33);
        yield 'cc';
        console.log('hello generator');
    }

    let iterator = gen();
    console.log(iterator);
    iterator.next();
    iterator.next();

    //遍历
    for (let v of gen()){
        console.log(v);
    }
</script>
</body>
</html>